//
//  StrategyOtherViewController.m
//  ErWa
//
//  Created by 王阳阳 on 16/3/11.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "StrategyOtherViewController.h"
#import "NewNestHeader.h"
#import "StrategyOtherTableViewCell.h"
#import "StrategyOtherModel.h"
#import "StrategyOtherDetailVC.h"
@interface StrategyOtherViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSMutableArray *dataArr;
@end

@implementation StrategyOtherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //名字
    self.navigationItem.title = self.titlename;
    //创建Tableview
    [self creatTableveiw];
    //数据解析
    [self data];
    
}
#pragma mark - 创建视图;
- (void)creatTableveiw{
    //创建tableview
    self.tableview = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableview.dataSource = self;//代理
    _tableview.delegate = self;
    _tableview.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_tableview];
    [_tableview registerClass:[StrategyOtherTableViewCell class] forCellReuseIdentifier:@"cell"];//重用池
}
#pragma mark - tableview必须实现的两个方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    StrategyOtherTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    //取消点击cell变灰
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    // 判断当前是什么模式
    BOOL model = [AccountManager sharedInstance].isNight;
    if (model == YES) {
        cell.backgroundColor = [UIColor grayColor];
        
    } else {
        cell.backgroundColor = [UIColor clearColor];
        
    }
    StrategyOtherModel *str = _dataArr[indexPath.item];
    cell.userNameLabel.text = str.name;//名字
    cell.contentLabel.text = str.content;//内容
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:str.backImgUrl]];//图片
    [cell.userImgview sd_setImageWithURL:[NSURL URLWithString:str.imgUrl]];//头像
    return cell;
}
#pragma mark - 数据解析
- (void)data{
    NSString *url =[[@"http://api.wsq.umeng.com/v2/topic/feeds?os=iOS&openudid=ab2665bf1689f98c2225a0fdbd3c01b8ed54b61c&sdkv=2.2.1&ak=5636cff167e58ef91b0001ae&de=iPhone5,4&mac=02:00:00:00:00:00&uid=56a330927019c97215dad1ed&topic_id=" stringByAppendingString:self.str] stringByAppendingString:@"&count=20"];//网址
    [AFNetworking GETWithURL:url completion:^(id result) {
        self.dataArr = [StrategyOtherModel modelHanderWithArray:result[@"items"]];
        [_tableview reloadData];//刷新
    }];
}
#pragma mark - / 设置cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return self.view.frame.size.height / 2;
}
#pragma mark - tableview点击跳转页面
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    StrategyOtherDetailVC *detailVc = [[StrategyOtherDetailVC alloc]init];
    detailVc.modal = _dataArr[indexPath.row];
    [self.navigationController pushViewController:detailVc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
